package com.woniuxy.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * description: SwaggerConfig <br>
 * date: 2021/12/27 7:30 下午 <br>
 * author: shesaifei <br>
 * version: 1.0 <br>
 */
@Configuration
@EnableSwagger2 //开启Swagger文档功能 注意，如果pom文件中spring-boot-starter-parent是2.6的必须降版本到2.56这是最高版本
public class SwaggerConfig {
    //1、配置应用程序说明:对当前项目简单描述

    @Bean
    public ApiInfo apiInfo(){
        return new ApiInfoBuilder().
                title("XX项目接口文档").
                description("该文档对XXX项目做了xx描述").
                version("接口版本 v1。0").build();
    }

    //2、指定为项目中哪些接口生成接口文档
    @Bean
    public Docket docket(ApiInfo apiInfo){
        return  new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.woniuxy.controller"))
                .apis(RequestHandlerSelectors.any())//选所有Controller
                .paths(PathSelectors.any())//选择所有路径
                .build();
    }


}
